/// 错误类型分类
#[derive(Debug, Clone, PartialEq)]
pub enum ErrorKind {
    // 词法分析错误 (MY001-MY099)
    LexicalError,        // 无法识别的字符 (MY001)
    UnterminatedString,  // 字符串未闭合 (MY002)
    InvalidNumberFormat, // 无效的数字格式 (MY003)
    InvalidIdentifier,   // 无效的标识符 (MY004)
    UnterminatedComment, // 注释未闭合 (MY005)

    // 语法分析错误 (MY100-MY199)
    SyntaxError,        // 一般语法错误 (MY100)
    UnexpectedToken,    // 期望某个 token 但得到另一个 (MY101)
    MissingToken,       // 缺少必需的 token (MY102)
    UnbalancedBrackets, // 括号不匹配 (MY103)
    InvalidStatement,   // 无效的语句 (MY104)
    UnexpectedEOF,      // 意外的文件结束 (MY105)
    InvalidIndentation, // 无效的缩进 (MY106)

    // 语义分析错误 (MY200-MY299)
    SemanticError,           // 一般语义错误 (MY200)
    UndefinedIdentifier,     // 未定义的标识符 (MY201)
    AlreadyDefined,          // 重复定义 (MY202)
    TypeMismatch,            // 类型不匹配 (MY203)
    ArgumentMismatch,        // 参数数量不匹配 (MY204)
    InvalidType,             // 无效的类型 (MY205)
    InvalidFunctionCall,     // 无效的函数调用 (MY206)
    UndefinedFunction,       // 未定义的函数 (MY207)
    InvalidAssignment,       // 无效的赋值 (MY208)
    OutOfScope,              // 超出作用域 (MY209)
    ConstantReassignment,    // 常量重新赋值 (MY210)
    InvalidInheritance,      // 无效的继承关系 (MY211)
    InterfaceNotImplemented, // 接口未实现 (MY212)
    GenericError,            // 泛型相关错误 (MY213)
    InvalidOverride,         // 无效的方法重写 (MY214)
    AccessControlError,      // 访问控制错误 (MY215)

    // 运行时错误 (MY300-MY399)
    RuntimeError,           // 一般运行时错误 (MY300)
    IndexOutOfBounds,       // 数组越界 (MY301)
    DivisionByZero,         // 除以零 (MY302)
    NullReference,          // 空引用 (MY303)
    InvalidOperation,       // 无效操作 (MY304)
    StackOverflow,          // 栈溢出 (MY305)
    RecursionDepthExceeded, // 递归深度超过限制 (MY306)
    FileNotFound,           // 文件未找到 (MY307)
    PermissionDenied,       // 权限被拒绝 (MY308)
    Timeout,                // 操作超时 (MY309)

    // 模块和导入错误 (MY400-MY499)
    ImportError,           // 模块导入错误 (MY400)
    ModuleNotFound,        // 找不到模块 (MY401)
    ExportError,           // 导出错误 (MY402)
    CircularImport,        // 循环导入 (MY403)
    InvalidModule,         // 无效的模块 (MY404)
    ModuleVersionMismatch, // 模块版本不匹配 (MY405)
    MissingExport,         // 缺少导出 (MY406)

    // IO 错误 (MY500-MY599)
    IOError,        // 文件读写错误 (MY500)
    ReadError,      // 读取错误 (MY501)
    WriteError,     // 写入错误 (MY502)
    FileExists,     // 文件已存在 (MY503)
    InvalidPath,    // 无效的路径 (MY504)
    DirectoryError, // 目录错误 (MY505)
    EncodingError,  // 编码错误 (MY506)

    // 警告和信息错误 (MY600-MY699)
    DeprecatedFeature,    // 使用了过时的特性 (MY600)
    UnusedVariable,       // 未使用的变量 (MY601)
    UnusedImport,         // 未使用的导入 (MY602)
    UnreachableCode,      // 不可达代码 (MY603)
    UnusedFunction,       // 未使用的函数 (MY604)
    ShadowingVariable,    // 变量阴影 (MY605)
    PerformanceWarning,   // 性能警告 (MY606)
    CodeStyleWarning,     // 代码风格警告 (MY607)
    DeprecatedSyntax,     // 使用了过时的语法 (MY608)
    UnusedParameter,      // 未使用的参数 (MY609)
    MissingDocumentation, // 缺少文档 (MY610)

    // 信息提示 (MY700-MY799)
    InfoMessage,      // 一般信息提示 (MY700)
    OptimizationHint, // 优化建议 (MY701)
    VersionInfo,      // 版本信息 (MY702)
    DebugInfo,        // 调试信息 (MY703)
    UsageInfo,        // 使用信息 (MY704)
}

impl ErrorKind {
    /// 获取错误代码
    pub fn code(&self) -> &'static str {
        match self {
            // 词法分析错误
            ErrorKind::LexicalError => "MY001",
            ErrorKind::UnterminatedString => "MY002",
            ErrorKind::InvalidNumberFormat => "MY003",
            ErrorKind::InvalidIdentifier => "MY004",
            ErrorKind::UnterminatedComment => "MY005",

            // 语法分析错误
            ErrorKind::SyntaxError => "MY100",
            ErrorKind::UnexpectedToken => "MY101",
            ErrorKind::MissingToken => "MY102",
            ErrorKind::UnbalancedBrackets => "MY103",
            ErrorKind::InvalidStatement => "MY104",
            ErrorKind::UnexpectedEOF => "MY105",
            ErrorKind::InvalidIndentation => "MY106",

            // 语义分析错误
            ErrorKind::SemanticError => "MY200",
            ErrorKind::UndefinedIdentifier => "MY201",
            ErrorKind::AlreadyDefined => "MY202",
            ErrorKind::TypeMismatch => "MY203",
            ErrorKind::ArgumentMismatch => "MY204",
            ErrorKind::InvalidType => "MY205",
            ErrorKind::InvalidFunctionCall => "MY206",
            ErrorKind::UndefinedFunction => "MY207",
            ErrorKind::InvalidAssignment => "MY208",
            ErrorKind::OutOfScope => "MY209",
            ErrorKind::ConstantReassignment => "MY210",
            ErrorKind::InvalidInheritance => "MY211",
            ErrorKind::InterfaceNotImplemented => "MY212",
            ErrorKind::GenericError => "MY213",
            ErrorKind::InvalidOverride => "MY214",
            ErrorKind::AccessControlError => "MY215",

            // 运行时错误
            ErrorKind::RuntimeError => "MY300",
            ErrorKind::IndexOutOfBounds => "MY301",
            ErrorKind::DivisionByZero => "MY302",
            ErrorKind::NullReference => "MY303",
            ErrorKind::InvalidOperation => "MY304",
            ErrorKind::StackOverflow => "MY305",
            ErrorKind::RecursionDepthExceeded => "MY306",
            ErrorKind::FileNotFound => "MY307",
            ErrorKind::PermissionDenied => "MY308",
            ErrorKind::Timeout => "MY309",

            // 模块错误
            ErrorKind::ImportError => "MY400",
            ErrorKind::ModuleNotFound => "MY401",
            ErrorKind::ExportError => "MY402",
            ErrorKind::CircularImport => "MY403",
            ErrorKind::InvalidModule => "MY404",
            ErrorKind::ModuleVersionMismatch => "MY405",
            ErrorKind::MissingExport => "MY406",

            // IO 错误
            ErrorKind::IOError => "MY500",
            ErrorKind::ReadError => "MY501",
            ErrorKind::WriteError => "MY502",
            ErrorKind::FileExists => "MY503",
            ErrorKind::InvalidPath => "MY504",
            ErrorKind::DirectoryError => "MY505",
            ErrorKind::EncodingError => "MY506",

            // 警告和信息错误
            ErrorKind::DeprecatedFeature => "MY600",
            ErrorKind::UnusedVariable => "MY601",
            ErrorKind::UnusedImport => "MY602",
            ErrorKind::UnreachableCode => "MY603",
            ErrorKind::UnusedFunction => "MY604",
            ErrorKind::ShadowingVariable => "MY605",
            ErrorKind::PerformanceWarning => "MY606",
            ErrorKind::CodeStyleWarning => "MY607",
            ErrorKind::DeprecatedSyntax => "MY608",
            ErrorKind::UnusedParameter => "MY609",
            ErrorKind::MissingDocumentation => "MY610",

            // 信息提示
            ErrorKind::InfoMessage => "MY700",
            ErrorKind::OptimizationHint => "MY701",
            ErrorKind::VersionInfo => "MY702",
            ErrorKind::DebugInfo => "MY703",
            ErrorKind::UsageInfo => "MY704",
        }
    }

    /// 获取错误类型的描述
    pub fn description(&self) -> &'static str {
        match self {
            // 词法分析错误
            ErrorKind::LexicalError => "词法错误",
            ErrorKind::UnterminatedString => "字符串未闭合",
            ErrorKind::InvalidNumberFormat => "无效的数字格式",
            ErrorKind::InvalidIdentifier => "无效的标识符",
            ErrorKind::UnterminatedComment => "注释未闭合",

            // 语法分析错误
            ErrorKind::SyntaxError => "语法错误",
            ErrorKind::UnexpectedToken => "意外的标记",
            ErrorKind::MissingToken => "缺少标记",
            ErrorKind::UnbalancedBrackets => "括号不匹配",
            ErrorKind::InvalidStatement => "无效的语句",
            ErrorKind::UnexpectedEOF => "意外的文件结束",
            ErrorKind::InvalidIndentation => "无效的缩进",

            // 语义分析错误
            ErrorKind::SemanticError => "语义错误",
            ErrorKind::UndefinedIdentifier => "未定义的标识符",
            ErrorKind::AlreadyDefined => "重复定义",
            ErrorKind::TypeMismatch => "类型不匹配",
            ErrorKind::ArgumentMismatch => "参数不匹配",
            ErrorKind::InvalidType => "无效的类型",
            ErrorKind::InvalidFunctionCall => "无效的函数调用",
            ErrorKind::UndefinedFunction => "未定义的函数",
            ErrorKind::InvalidAssignment => "无效的赋值",
            ErrorKind::OutOfScope => "超出作用域",
            ErrorKind::ConstantReassignment => "常量重新赋值",
            ErrorKind::InvalidInheritance => "无效的继承关系",
            ErrorKind::InterfaceNotImplemented => "接口未实现",
            ErrorKind::GenericError => "泛型相关错误",
            ErrorKind::InvalidOverride => "无效的方法重写",
            ErrorKind::AccessControlError => "访问控制错误",

            // 运行时错误
            ErrorKind::RuntimeError => "运行时错误",
            ErrorKind::IndexOutOfBounds => "索引越界",
            ErrorKind::DivisionByZero => "除以零",
            ErrorKind::NullReference => "空引用",
            ErrorKind::InvalidOperation => "无效操作",
            ErrorKind::StackOverflow => "栈溢出",
            ErrorKind::RecursionDepthExceeded => "递归深度超过限制",
            ErrorKind::FileNotFound => "文件未找到",
            ErrorKind::PermissionDenied => "权限被拒绝",
            ErrorKind::Timeout => "操作超时",

            // 模块错误
            ErrorKind::ImportError => "导入错误",
            ErrorKind::ModuleNotFound => "模块未找到",
            ErrorKind::ExportError => "导出错误",
            ErrorKind::CircularImport => "循环导入",
            ErrorKind::InvalidModule => "无效的模块",
            ErrorKind::ModuleVersionMismatch => "模块版本不匹配",
            ErrorKind::MissingExport => "缺少导出",

            // IO 错误
            ErrorKind::IOError => "IO错误",
            ErrorKind::ReadError => "读取错误",
            ErrorKind::WriteError => "写入错误",
            ErrorKind::FileExists => "文件已存在",
            ErrorKind::InvalidPath => "无效的路径",
            ErrorKind::DirectoryError => "目录错误",
            ErrorKind::EncodingError => "编码错误",

            // 警告和信息错误
            ErrorKind::DeprecatedFeature => "使用了过时的特性",
            ErrorKind::UnusedVariable => "未使用的变量",
            ErrorKind::UnusedImport => "未使用的导入",
            ErrorKind::UnreachableCode => "不可达代码",
            ErrorKind::UnusedFunction => "未使用的函数",
            ErrorKind::ShadowingVariable => "变量阴影",
            ErrorKind::PerformanceWarning => "性能警告",
            ErrorKind::CodeStyleWarning => "代码风格警告",
            ErrorKind::DeprecatedSyntax => "使用了过时的语法",
            ErrorKind::UnusedParameter => "未使用的参数",
            ErrorKind::MissingDocumentation => "缺少文档",

            // 信息提示
            ErrorKind::InfoMessage => "信息提示",
            ErrorKind::OptimizationHint => "优化建议",
            ErrorKind::VersionInfo => "版本信息",
            ErrorKind::DebugInfo => "调试信息",
            ErrorKind::UsageInfo => "使用信息",
        }
    }
}
